class EditorManager {
    static tempLayerIndex = null;//弹出层索引
    static tempTraitsLayerIndex = null;//特性弹出层索引
    static tempTraitsTableLayerIndex = null;//特性表格弹出层索引
    static tempItemListElement = null;//临时存储是哪个元素调出的项目列表
    static tempTableEditIndex = null;//临时存储表格行编辑索引
    static systemData = null;
    static stateData = null;
    static skillData = null;

    static iconPage = 1;

    //测试用
    static url = "./testData/"
    // static url = ".。/data/"

    static imgUrl = "./testData/IconSet.png"

    //未保存缓存数据
    static cache = {}

    /**
     * 输出data
     */
    static exportData() {
        const form = layui.form;
        const table = layui.table;

        //基础信息
        const baseInfo = form.val("baseInfo");
        const {id, name, textColor, description} = baseInfo;
        const iconIndex = Number(baseInfo.iconIndex) || 0;

        //词缀信息
        const affixsInfo = form.val("affixsInfo");
        const {nameShow, nameType, affixType} = affixsInfo;
        //拓展属性
        const expandParam = form.val("expandParam");
        const quality = Number(expandParam.quality) || 0;
        const linkedEquipSuit = Number(expandParam.linkedEquipSuit) || 0;
        const boostAdd = Number(expandParam.boostAdd) || 0;
        const priceMin = Number(expandParam.priceMin) || 0;
        const priceMax = Number(expandParam.priceMax) || 0;
        //自定义效果
        const customParam = form.val("customParam");
        const {note, customEffect, require} = customParam;
        //一般属性
        const paramsRandom = table.getData("param");
        const ratesRandom = table.getData("rateParam");
        //特性需要处理
        const traitsRandom = [];
        for (const item of table.getData("traitsParam")) {
            const data = JSON.parse(item.traits)
            traitsRandom.push(data);
        }
        //暂留
        const extrasRandom = [];
        return {
            id,
            name,
            iconIndex,
            textColor,
            description,
            nameShow,
            nameType,
            affixType,
            quality,
            linkedEquipSuit,
            boostAdd,
            priceMin,
            priceMax,
            note,
            customEffect,
            require,
            paramsRandom,
            ratesRandom,
            traitsRandom,
            extrasRandom
        }
    }

    /**
     * 加载所有数据
     */
    static async loadAllData() {
        await Promise.all([
            this.loadSystemData(),
            this.loadStateData(),
            this.loadSkillData(),
            this.loadEquipAffixesJson()
        ])
        this.setItemList();
        this.traitsInterpret();
        this.traitsTextToDataId();
        this.loadIconImg();
    }

    /**
     * 加载系统数据
     */
    static async loadSystemData() {
        const response = await fetch(`${this.url}System.json`);
        if (response.ok) {
            this.systemData = await response.json();
            this.setTypeElement();
        } else {
            alert("未找到System.json文件,请确认编辑器目录是否放置在rm工程跟目录下");
        }
    }

    /**
     * 加载状态数据
     */
    static async loadStateData() {
        const response = await fetch(`${this.url}States.json`);
        if (response.ok) {
            this.stateData = await response.json();
            // this.setStateElement();
        } else {
            alert("未找到States.json文件,请确认编辑器目录是否放置在rm工程跟目录下");
        }
    }

    /**
     * 加载技能数据
     */
    static async loadSkillData() {
        const response = await fetch(`${this.url}Skills.json`);
        if (response.ok) {
            this.skillData = await response.json();
        } else {
            alert("未找到Skills.json文件,请确认编辑器目录是否放置在rm工程跟目录下");
        }
    }

    /**
     * 加载独立物品词条json
     */
    static async loadEquipAffixesJson() {
        const response = await fetch(`${this.url}EquipAffixes.json`);
        if (response.ok) {
            this.data = await response.json();
        } else {
            alert("未找到EquipAffixes.json文件,请确认编辑器目录是否放置在rm工程跟目录下");
        }
    }

    /**
     * 加载图标图片
     */
    static loadIconImg() {
        //加载图标图片
        window.iconImg = new Image();
        window.iconImg.src = this.imgUrl;
        //canvas监听事件
        document.getElementById("canvas").addEventListener("click", function (e) {
            layer.closeAll();
            const x = Math.floor(e.offsetX / 32);
            const y = Math.floor(e.offsetY / 32);
            const iconIndex = (EditorManager.iconPage - 1) * 256 + y * 16 + x;
            document.getElementById("input-icon").value = iconIndex;
        })
    }

    /**
     * 根据systemData设置选项相关页面元素
     */
    static setTypeElement() {
        const ele = document.getElementById("traits-11");
        const ele2 = document.getElementById("traits-31");
        //属性选项
        const types = this.systemData.elements;
        for (let i = 1; i < types.length; i++) {
            const option = document.createElement("option");
            option.value = i.toString();
            option.innerHTML = types[i];
            ele.appendChild(option);
            ele2.appendChild(option.cloneNode(true));
        }
        //技能类型选项
        const ele3 = document.getElementById("traits-41");
        const ele4 = document.getElementById("traits-42");
        const skillTypes = this.systemData.skillTypes;
        for (let i = 1; i < skillTypes.length; i++) {
            const option = document.createElement("option");
            option.value = i.toString();
            option.innerHTML = skillTypes[i];
            ele3.appendChild(option);
            ele4.appendChild(option.cloneNode(true));
        }
        //装备武器类型
        const ele5 = document.getElementById("traits-51");
        const weaponTypes = this.systemData.weaponTypes;
        for (let i = 1; i < weaponTypes.length; i++) {
            const option = document.createElement("option");
            option.value = i.toString();
            option.innerHTML = weaponTypes[i];
            ele5.appendChild(option);
        }
        //装备防具类型
        const ele6 = document.getElementById("traits-52");
        const armorTypes = this.systemData.armorTypes;
        for (let i = 1; i < armorTypes.length; i++) {
            const option = document.createElement("option");
            option.value = i.toString();
            option.innerHTML = armorTypes[i];
            ele6.appendChild(option);
        }
        //装备槽类型
        const ele7 = document.getElementById("traits-53");
        const ele8 = document.getElementById("traits-54");
        const equipTypes = this.systemData.equipTypes;
        for (let i = 1; i < equipTypes.length; i++) {
            const option = document.createElement("option");
            option.value = i.toString();
            option.innerHTML = equipTypes[i];
            ele7.appendChild(option);
            ele8.appendChild(option.cloneNode(true));
        }
    }

    /**
     * 根据data设置项目id查询页面树列表
     */
    static setItemList() {
        const stateData = this.stateData.filter(item => !!item?.name);
        const skillData = this.skillData.filter(item => !!item?.name);
        const stateNum = stateData.length - 1;
        const skillNum = skillData.length - 1;
        const statePageNum = Math.ceil(stateNum / 100);
        const skillPageNum = Math.ceil(skillNum / 100);
        let stateList = [], skillList = [];
        //状态
        for (let i = 1; i <= statePageNum; i++) {
            const children = [];
            //开始索引
            const start = (i - 1) * 100;
            //结束索引
            const end = i * 100;
            const title = `${start + 1}-${end}`;
            const id = `state-page-${i}`
            const obj = {title, id, children}
            //添加分页的数据
            for (let j = 0; j <= 100; j++) {
                const index = (i - 1) * 100 + j;
                const state = stateData[index];
                if (!!state) {
                    const name = state.name;
                    const id = `${state.id}:${name}`;
                    const title = `${name}`;
                    const obj = {title, id};
                    children.push(obj);
                }
            }
            stateList.push(obj);
        }
        //技能
        for (let i = 1; i <= skillPageNum; i++) {
            const children = [];
            //开始索引
            const start = (i - 1) * 100;
            //结束索引
            const end = i * 100;
            const title = `${start + 1}-${end}`;
            const id = `skill-page-${i}`;
            const obj = {title, id, children}
            //添加分页的数据
            for (let j = 0; j <= 100; j++) {
                const index = (i - 1) * 100 + j;
                const skill = skillData[index];
                if (!!skill) {
                    const name = skill.name;
                    const id = `${skill.id}:${name}`;
                    const title = `${name}`;
                    const obj = {title, id};
                    children.push(obj);
                }
            }
            skillList.push(obj);
        }
        //状态
        layui.use(function () {
            const tree = layui.tree;
            const layer = layui.layer;
            // 渲染
            tree.render({
                elem: '#ID-tree-item-state-list',
                data: [{"title": "状态", "id": "state", "children": stateList}],
                click: function (obj) {
                    if (!!obj.data.children) return;
                    const value = EditorManager.tempItemListElement.value;
                    EditorManager.tempItemListElement.value += value === "" ? `${obj.data.id}` : `,${obj.data.id}`;
                    EditorManager.tempItemListElement = null;
                    layer.close(EditorManager.tempLayerIndex);
                    EditorManager.tempLayerIndex = null;
                }
            })
        })
        //技能
        layui.use(function () {
            const tree = layui.tree;
            const layer = layui.layer;
            // 渲染
            tree.render({
                elem: '#ID-tree-item-skill-list',
                data: [{"title": "技能", "id": "skill", "children": skillList}],
                click: function (obj) {
                    if (!!obj.data.children) return;
                    const value = EditorManager.tempItemListElement.value;
                    EditorManager.tempItemListElement.value += value === "" ? `${obj.data.id}` : `,${obj.data.id}`;
                    EditorManager.tempItemListElement = null;
                    layer.close(EditorManager.tempLayerIndex);
                    EditorManager.tempLayerIndex = null;
                }
            })
        })
    }

    /**
     * 初始化目录
     */
    static initDirectory() {
        //获取目录容器
        const container = document.getElementById("directory");
        //以100为单位分割总项目，计算页数
        const pageNum = Math.ceil(this.data.length / 100);
        //按页
        for (let i = 1; i <= pageNum; i++) {
            //开始索引
            const start = (i - 1) * 100;
            //结束索引
            const end = i * 100;
            const li = document.createElement("li");
            const title = document.createElement("div");
            const list = document.createElement("ul");
            li.className = "layui-menu-item-group";
            title.className = "layui-menu-body-title";
            title.innerHTML = `${start + 1}-${end}`;
            li.appendChild(title);
            li.appendChild(list);
            container.appendChild(li);
            //添加每页的数据
            for (let j = 1; j <= 100; j++) {
                const no = (i - 1) * 100 + j;
                if (!this.data[no]) continue;
                const name = `ID-${no}-${this.data[no]?.name}`;
                const li = document.createElement("li");
                const item = document.createElement("div");
                const a = document.createElement("a");
                li.setAttribute("lay-options", `{index: ${no}}`);
                li.id = `d-index-${no}`;
                item.className = "layui-menu-body-title";
                a.href = "javascript:void(0);";
                a.innerHTML = name;
                item.appendChild(a);
                li.appendChild(item);
                list.appendChild(li);
            }
        }
        this.renderDirectory();
    }

    /**
     * 渲染目录
     */
    static renderDirectory() {
        //动态生成的目录所以需要重新渲染
        // layui.element.render();
        layui.use(function () {
            const dropdown = layui.dropdown;
            const slider = layui.slider;
            //目录点击事件
            dropdown.on('click(directory)', function (options) {
                //面板存入临时数据
                const tempData = EditorManager.exportData();
                const {id, name} = tempData
                if (id !== "") EditorManager.cache[id] = tempData;
                //暂存数据
                if (!!id) {
                    EditorManager.cache[id] = tempData;
                }
                const {index} = options;
                //更新显示面板
                const newData = EditorManager.cache[index] ?? EditorManager.data[index];
                EditorManager.updatePanel(newData);
            })
        })
    }

    /**
     * 刷新目录
     */
    static refreshDirectory() {
        //获取目录容器
        const container = document.getElementById("directory");
        container.innerHTML = "";
        this.initDirectory();
    }

    /**
     * 更改目录最大值
     * @param {number} value 最大值
     */
    static changeItemMax(value) {
        const layer = layui.layer;
        const input = Number(value);
        if (!!input) {
            const num = Math.min(input, 1000);
            const data = [null];
            for (let i = 1; i <= num; i++) {
                //优先缓存
                data[i] = this.cache[i] ?? this.data[i] ?? this.nullData(i);
            }
            this.data = data;
            // this.save();
            this.refreshDirectory();
            return;
        }
        layer.msg("输入不合法");
    }

    /**
     * 空数据对象
     * @param {number} id id
     */
    static nullData(id) {
        const name = "";
        const iconIndex = 0;
        const textColor = "#FFFFFF";
        const description = "";
        const nameShow = "";
        const nameType = "";
        const affixType = "";
        const quality = 0;
        const linkedEquipSuit = 0;
        const boostAdd = 0;
        const priceMin = 0;
        const priceMax = 100;
        const note = "";
        const customEffect = "";
        const require = "";
        const paramsRandom = [];
        const ratesRandom = [];
        const traitsRandom = [];
        const extrasRandom = [];
        return {
            id,
            name,
            iconIndex,
            textColor,
            description,
            nameShow,
            nameType,
            affixType,
            quality,
            linkedEquipSuit,
            boostAdd,
            priceMin,
            priceMax,
            note,
            customEffect,
            require,
            paramsRandom,
            ratesRandom,
            traitsRandom,
            extrasRandom
        }
    }

    /**
     * 更新面板
     * @param {Object} data 装备词条数据
     */
    static updatePanel(data) {
        const form = layui.form;
        const table = layui.table;
        const {
            id,
            name,
            iconIndex,
            textColor,
            description,
            nameShow,
            nameType,
            affixType,
            quality,
            linkedEquipSuit,
            boostAdd,
            priceMin,
            priceMax,
            note,
            customEffect,
            require,
            paramsRandom,
            ratesRandom,
            traitsRandom,
            extrasRandom
        } = data;
        //基础信息
        form.val("baseInfo", {id, name, iconIndex, description});
        //颜色选择器重新渲染
        this.renderColorPicker(textColor)
        //词缀信息
        form.val("affixsInfo", {nameShow, nameType, affixType});
        //拓展属性
        form.val("expandParam", {quality, linkedEquipSuit, boostAdd, priceMin, priceMax});
        //自定义效果
        form.val("customParam", {note, customEffect, require});
        //一般属性表格
        table.reloadData("param", {
            data: paramsRandom
        })
        //倍率属性表格
        table.reloadData("rateParam", {
            data: ratesRandom
        })
        //特性属性表格
        table.reloadData("traitsParam", {
            data: traitsRandom.map(item => {
                this.addExplainParam(item);
                const traits = JSON.stringify(item);
                return {traits};
            })
        })
    }

    /**
     * 添加特性表格说明文本
     * @param {Object} obj 特性表格数据
     */
    static addExplainParam(obj) {
        for (const traits of obj) {
            const {code, dataIds, name} = traits;
            if (!!name) continue;
            traits.name = this.traitsCodeText[code] ?? "错误的特性code";
            traits.param = dataIds.map(item => {
                return this.traitsList[code][item];
            })
        }
    }

    /**
     * 保存
     */
    static save() {
        //暂存当前面板数据
        const tempData = EditorManager.exportData();
        const {id} = tempData;
        if (!!id) {
            EditorManager.cache[id] = tempData;
        }
        const data = [null];
        for (let i = 1; i < this.data.length; i++) {
            data[i] = this.cache[i] ?? this.data[i] ?? this.nullData(i);
            //去掉特性data中的解释性属性
            const {traitsRandom} = data[i];
            for (const arr of traitsRandom) {
                for (const item of arr) {
                    if (!!item.name) delete item.name;
                    if (!!item.param) delete item.param;
                }
            }
        }
        this.data = data;
    }

    /**
     * 保存到文件
     */
    static saveToFile() {
        this.save();
        const fileName = `EquipAffixes${Date.now()}.json`;
        const data = JSON.stringify(this.data, null, 2);
        if (!!window.require) {
            //nw环境
            const fs = require("fs");
            try {
                //防止有bug文件名加了时间戳暂时不覆盖
                fs.writeFileSync(`${this.url}${fileName}`, data);
            } catch (err) {
                console.log(err);
            }
        } else {
            //浏览器环境
            const blob = new Blob([data], {type: "text/json"});
            const a = document.createElement("a");
            a.download = `${fileName}`;
            a.style.display = "none";
            a.href = URL.createObjectURL(blob);
            a.click();
        }
    }

    /**
     * 渲染所有
     */
    static renderAll() {
        this.renderColorPicker("#FFFFFF");
        this.renderTable();
        //一般属性跟倍率属性的弹窗表单逻辑
        this.renderLayerForm();
        //特性弹窗相关逻辑
        this.renderTraitsLayerEvent();
        //加载元素事件
        this.addEleEvent();
    }

    /**
     * 渲染颜色选择器
     * @param {string} color 颜色
     */
    static renderColorPicker(color) {
        window['ID-colorpicker-form-color'].value = color;
        layui.use(function () {
            const colorpicker = layui.colorpicker;
            // 渲染
            colorpicker.render({ // eg1
                elem: '#ID-colorpicker-textColor',
                color: color, // hex
                done: function (color) {
                    window['ID-colorpicker-form-color'].value = color;
                }
            })
        })
    }

    /**
     * 渲染表格
     */
    static renderTable() {
        this.renderParamTable();
        this.renderRateParamTable();
        this.renderTraitsParamTable();
        this.renderTraitsParamChildrenTable();
    }

    /**
     * 渲染一般属性表格
     */
    static renderParamTable() {
        layui.use('table', function () {
            const table = layui.table;
            const layer = layui.layer;
            //layui需要手动引入jq
            const $ = layui.$;
            // 已知数据渲染
            table.render({
                elem: '#ID-table-param',
                toolbar: true,
                defaultToolbar: [{
                    title: '增加',
                    layEvent: 'addParam',
                    icon: 'layui-icon-addition',
                    onClick: function (data) {
                        //清空之前属性输入
                        window["layer-textarea-params"].value = "";
                        layer.open({
                            title: "设置一般属性参数",
                            type: 1,
                            area: ['500px', '500px'],
                            content: $('#ID-layer-param')
                        })
                    }
                }, {
                    title: '清空',
                    layEvent: 'clearParam',
                    icon: 'layui-icon-delete',
                    onClick: function (obj) {
                        //清空表格数据
                        layui.table.reloadData("param", {
                            data: []
                        })
                    }
                }],
                id: "param",
                css: [ // 设置单元格样式
                    // 取消默认的溢出隐藏，并设置适当高度
                    '.layui-table-cell{height: 50px; line-height: 40px;}',
                    '.layui-table-cell .layui-colorpicker{width: 38px; height: 38px;}',
                    '.layui-table-cell select{height: 36px; padding: 0 5px;}'
                ].join(''),
                cols: [[ //标题栏
                    {field: 'params', title: '属性组'},
                    {field: 'min', title: '最小值', width: 120},
                    {field: 'max', title: '最大值', width: 120},
                    {field: 'type', title: '类型', width: 120}
                ]],
                data: []
            })
            // 触发单元格工具删除事件
            table.on('tool(param)', function (obj) { // 双击 toolDouble
                // var data = obj.data; // 获得当前行数据
                if (obj.event === 'del') {
                    obj.del();
                }
            })
        })
    }

    /**
     * 渲染倍率属性表格
     */
    static renderRateParamTable() {
        layui.use('table', function () {
            const table = layui.table;
            const layer = layui.layer;
            //layui需要手动引入jq
            const $ = layui.$;
            // 已知数据渲染
            table.render({
                elem: '#ID-table-rate-param',
                toolbar: true,
                defaultToolbar: [{
                    title: '增加',
                    layEvent: 'addParam',
                    icon: 'layui-icon-addition',
                    onClick: function (data) {
                        //清空之前属性输入
                        window["layer-textarea-rate-params"].value = "";
                        layer.open({
                            title: "设置倍率属性参数",
                            type: 1,
                            area: ['500px', '500px'],
                            content: $('#ID-layer-rate-param')
                        })
                    }
                }, {
                    title: '清空',
                    layEvent: 'clearParam',
                    icon: 'layui-icon-delete',
                    onClick: function (obj) {
                        //清空表格数据
                        layui.table.reloadData("rateParam", {
                            data: []
                        })
                    }
                }],
                id: "rateParam",
                css: [ // 设置单元格样式
                    // 取消默认的溢出隐藏，并设置适当高度
                    '.layui-table-cell{height: 50px; line-height: 40px;}',
                    '.layui-table-cell .layui-colorpicker{width: 38px; height: 38px;}',
                    '.layui-table-cell select{height: 36px; padding: 0 5px;}'
                ].join(''),
                cols: [[ //标题栏
                    {field: 'params', title: '属性组'},
                    {field: 'min', title: '最小值', width: 120},
                    {field: 'max', title: '最大值', width: 120},
                    {field: 'type', title: '类型', width: 120}
                ]],
                data: []
            })
            // 触发单元格工具删除事件
            table.on('tool(rateParam)', function (obj) { // 双击 toolDouble
                // var data = obj.data; // 获得当前行数据
                if (obj.event === 'del') {
                    obj.del();
                }
            })
        })
    }

    /**
     * 渲染特性属性表格
     */
    static renderTraitsParamTable() {
        layui.use('table', function () {
            const table = layui.table;
            const layer = layui.layer;
            //layui需要手动引入jq
            const $ = layui.$;
            // 已知数据渲染
            table.render({
                elem: '#ID-table-traits-param',
                toolbar: true,
                defaultToolbar: [{
                    title: '增加',
                    layEvent: 'addParam',
                    icon: 'layui-icon-addition',
                    onClick: function (data) {
                        EditorManager.clearTableData("traitsParamChildren");
                        layer.open({
                            title: "设置特性属性参数",
                            type: 1,
                            area: ['1280px', '720px'],
                            content: $('#ID-layer-traits-table-params'),
                            btn: ['提交'],
                            btn1: function (index, layero, that) {
                                // console.log(index, layero, that)
                                const data = table.getData("traitsParamChildren");
                                if (data.length !== 0) {
                                    const traitsData = [...table.getData("traitsParam"), {"traits": JSON.stringify(data)}];
                                    table.reloadData("traitsParam", {
                                        data: traitsData
                                    })
                                }
                                layer.close(index);
                            }
                        })
                    }
                }, {
                    title: '清空',
                    layEvent: 'clearParam',
                    icon: 'layui-icon-delete',
                    onClick: function (obj) {
                        // 清空表格数据
                        table.reloadData("traitsParam", {
                            data: []
                        })
                    }
                }],
                id: "traitsParam",
                css: [ // 设置单元格样式
                    // 取消默认的溢出隐藏，并设置适当高度
                    '.layui-table-cell{height: 50px; line-height: 40px;}',
                    '.layui-table-cell .layui-colorpicker{width: 38px; height: 38px;}',
                    '.layui-table-cell select{height: 36px; padding: 0 5px;}'
                ].join(''),
                cols: [[ //标题栏
                    {field: 'traits', title: '特性组'},
                    {fixed: 'right', title: '操作', width: 150, minWidth: 150, toolbar: '#TraitsBar'}
                ]],
                data: []
            })
            // 触发单元格工具删除事件
            table.on('tool(traitsParam)', function (obj) { // 双击 toolDouble
                // var data = obj.data; // 获得当前行数据
                if (obj.event === 'del') {
                    obj.del();
                } else if (obj.event === 'edit') {
                    const data = JSON.parse(obj.data.traits);
                    EditorManager.tempTableEditIndex = obj.index;
                    table.reloadData("traitsParamChildren", {
                        data: data
                    })
                    layer.open({
                        title: "设置特性属性参数",
                        type: 1,
                        area: ['1280px', '720px'],
                        content: $('#ID-layer-traits-table-params'),
                        btn: ['修改'],
                        btn1: function (index, layero, that) {
                            // console.log(index, layero, that)
                            const data = table.getData("traitsParamChildren");
                            if (data.length !== 0) {
                                table.updateRow("traitsParam", {
                                    index: EditorManager.tempTableEditIndex,
                                    data: {"traits": JSON.stringify(data)}
                                })
                            } else obj.del();
                            layer.close(index);
                        }
                    })
                }
            })
        })
    }

    /**
     * 渲染特性组子属性表格
     */
    static renderTraitsParamChildrenTable() {
        layui.use('table', function () {
            const table = layui.table;
            const layer = layui.layer;
            //layui需要手动引入jq
            const $ = layui.$;
            // 已知数据渲染
            table.render({
                elem: '#ID-table-traits-param-children',
                toolbar: true,
                defaultToolbar: [{
                    title: '增加',
                    layEvent: 'addParam',
                    icon: 'layui-icon-addition',
                    onClick: function (data) {
                        EditorManager.clearDisplayText();
                        EditorManager.tempTraitsLayerIndex = layer.open({
                            title: "选择特性",
                            type: 1,
                            area: ['600px', '800px'],
                            content: $('#ID-layer-traits-param'),
                            btn: ['清空'],
                            btn1: function (index, layero, that) {
                                EditorManager.clearDisplayText();
                            }
                        })
                    }
                }, {
                    title: '清空',
                    layEvent: 'clearParam',
                    icon: 'layui-icon-delete',
                    onClick: function (obj) {
                        //清空表格数据
                        layui.table.reloadData("traitsParamChildren", {
                            data: []
                        })
                    }
                }],
                id: "traitsParamChildren",
                css: [ // 设置单元格样式
                    // 取消默认的溢出隐藏，并设置适当高度
                    '.layui-table-cell{height: 50px; line-height: 40px;}',
                    '.layui-table-cell .layui-colorpicker{width: 38px; height: 38px;}',
                    '.layui-table-cell select{height: 36px; padding: 0 5px;}'
                ].join(''),
                // pagebar: '#ID-layer-traits-table-params-button',
                cols: [[ //标题栏
                    // 隐藏数据
                    // {field: 'code', title: '特性代码'},
                    // {field: 'dataIds', title: '特性数据id代码', width: 150},
                    {field: 'name', title: '特性', width: 150},
                    {field: 'param', title: '属性'},
                    {field: 'min', title: '最小值', width: 120, edit: 'text'},
                    {field: 'max', title: '最大值', width: 120, edit: 'text'}
                ]],
                data: [],
                page: true, // 是否显示分页
                limits: [10, 15, 20],
                limit: 10 // 每页默认显示的数量
            })
        })
    }

    /**
     * 渲染弹出表单
     */
    static renderLayerForm() {
        layui.use("form", function () {
            const form = layui.form;
            const layer = layui.layer;
            const util = layui.util;
            const $ = layui.$;
            //图标选择
            util.on('lay-on', {
                "icon": function (othis) {
                    EditorManager.drawIcon();
                    layer.open({
                        title: "图标选择",
                        type: 1,
                        area: ['512px', '650px'],
                        content: $("#ID-layer-icon"),
                        btn: ['上一页', "下一页"],
                        btn1: function (index, layero, that) {
                            const page = Math.max(EditorManager.iconPage - 1, 1);
                            if (page !== EditorManager.iconPage) {
                                EditorManager.iconPage = page;
                                EditorManager.drawIcon();
                            }
                            return false;
                        },
                        btn2: function (index, layero, that) {
                            const page = Math.min(EditorManager.iconPage + 1, Math.ceil(iconImg.height / 512));
                            if (page !== EditorManager.iconPage) {
                                EditorManager.iconPage = page;
                                EditorManager.drawIcon();
                            }
                            return false;
                        }
                    })
                }
            });
            //表单提交按钮
            form.on('submit(paramSubmit)', function (data) {
                EditorManager.addParamTableCol(data.field);
                layer.closeAll("page");
                return false; // 阻止默认 form 跳转
            })
            form.on('submit(rateParamSubmit)', function (data) {
                EditorManager.addRateParamTableCol(data.field);
                layer.closeAll("page");
                return false; // 阻止默认 form 跳转
            })
            //设置表单里属性选择框点击的回调
            form.on('select(param-list)', function (data) {
                const {value} = data;
                let params = window["layer-textarea-params"].value;
                if (value === "clear") {
                    window["layer-textarea-params"].value = "";
                    return;
                }
                if (params !== "") {
                    params += `,${value}`;
                } else params = value;
                window["layer-textarea-params"].value = params;
            })
            form.on('select(rate-param-list)', function (data) {
                const {value} = data;
                let params = window["layer-textarea-rate-params"].value;
                if (value === "clear") {
                    window["layer-textarea-rate-params"].value = "";
                    return;
                }
                if (params !== "") {
                    params += `,${value}`;
                } else params = value;
                window["layer-textarea-rate-params"].value = params;
            })
        })

    }

    /**
     * 添加属性组到表格
     * @param {Object} data 属性组数据
     */
    static addParamTableCol(data) {
        if (!!data && data.param !== "") {
            const table = layui.table;
            const layer = layui.layer;
            const {type, paramMin, paramMax} = data;
            const min = Number(paramMin) || 0;
            const max = Number(paramMax) || 100;
            const params = data.params.split(",");
            if (!!params[0]) {
                table.reloadData("param", {
                    data: [...table.getData("param"), {params, type, min, max}]
                })
            } else layer.msg('属性组不能为空');
        }
    }

    /**
     * 添加倍率属性组到表格
     * @param {Object} data 属性组数据
     */
    static addRateParamTableCol(data) {
        if (!!data && data.param !== "") {
            const table = layui.table;
            const layer = layui.layer;
            const {type, paramMin, paramMax} = data;
            const min = Number(paramMin) || 0;
            const max = Number(paramMax) || 100;
            const params = data.params.split(",");
            if (!!params[0]) {
                table.reloadData("rateParam", {
                    data: [...table.getData("rateParam"), {params, type, min, max}]
                })
            } else layer.msg('属性组不能为空');
        }
    }

    /**
     * 渲染特性窗口项目事件
     */
    static renderTraitsLayerEvent() {
        layui.use(function () {
            const form = layui.form;
            const layer = layui.layer;
            const util = layui.util;
            // const table = layui.table;
            const $ = layui.$;
            //提交按钮点击
            util.on('lay-on', {
                // 属性有效度
                "traits-code-11": EditorManager.traitsLayerClick11,
                "traits-code-12": EditorManager.traitsLayerClick12,
                "traits-code-13": EditorManager.traitsLayerClick13,
                "traits-code-14": EditorManager.traitsLayerClick14,
                "traits-code-31": EditorManager.traitsLayerClick31,
                "traits-code-32": EditorManager.traitsLayerClick32,
                "traits-code-33": EditorManager.traitsLayerClick33,
                "traits-code-34": EditorManager.traitsLayerClick34,
                "traits-code-35": EditorManager.traitsLayerClick35,
                "traits-code-41": EditorManager.traitsLayerClick41,
                "traits-code-42": EditorManager.traitsLayerClick42,
                "traits-code-43": EditorManager.traitsLayerClick43,
                "traits-code-44": EditorManager.traitsLayerClick44,
                "traits-code-51": EditorManager.traitsLayerClick51,
                "traits-code-52": EditorManager.traitsLayerClick52,
                "traits-code-53": EditorManager.traitsLayerClick53,
                "traits-code-54": EditorManager.traitsLayerClick54,
                "traits-code-55": EditorManager.traitsLayerClick55,
                "traits-code-61": EditorManager.traitsLayerClick61,
                "traits-code-62": EditorManager.traitsLayerClick62,
                "traits-code-63": EditorManager.traitsLayerClick63,
                "traits-code-64": EditorManager.traitsLayerClick64
            })
            // 特性输入框点击打开项目选择窗口
            form.on('input-affix(code13)', function (data) {
                EditorManager.tempItemListElement = document.getElementById(`traits-show-${data.elem.name}`);
                EditorManager.tempLayerIndex = layer.open({
                    title: "项目列表",
                    type: 1,
                    area: ['500px', '80%'],
                    content: $('#ID-layer-item-state-list')
                })
            })
            form.on('input-affix(code14)', function (data) {
                EditorManager.tempItemListElement = document.getElementById(`traits-show-${data.elem.name}`);
                EditorManager.tempLayerIndex = layer.open({
                    title: "项目列表",
                    type: 1,
                    area: ['500px', '80%'],
                    content: $('#ID-layer-item-state-list')
                })
            })
            //攻击时状态
            form.on('input-affix(code32)', function (data) {
                EditorManager.tempItemListElement = document.getElementById(`traits-show-${data.elem.name}`);
                EditorManager.tempLayerIndex = layer.open({
                    title: "项目列表",
                    type: 1,
                    area: ['500px', '80%'],
                    content: $('#ID-layer-item-state-list')
                })
            })

            //攻击技能
            form.on('input-affix(code35)', function (data) {
                EditorManager.tempItemListElement = document.getElementById(`traits-show-${data.elem.name}`);
                EditorManager.tempLayerIndex = layer.open({
                    title: "项目列表",
                    type: 1,
                    area: ['500px', '80%'],
                    content: $('#ID-layer-item-skill-list')
                })
            })
            //添加技能
            form.on('input-affix(code43)', function (data) {
                EditorManager.tempItemListElement = document.getElementById(`traits-show-${data.elem.name}`);
                EditorManager.tempLayerIndex = layer.open({
                    title: "项目列表",
                    type: 1,
                    area: ['500px', '80%'],
                    content: $('#ID-layer-item-skill-list')
                })
            })
            //封印技能
            form.on('input-affix(code44)', function (data) {
                EditorManager.tempItemListElement = document.getElementById(`traits-show-${data.elem.name}`);
                EditorManager.tempLayerIndex = layer.open({
                    title: "项目列表",
                    type: 1,
                    area: ['500px', '80%'],
                    content: $('#ID-layer-item-skill-list')
                })
            })
            //选项点击事件
            const selectSymbolArr = ['select(属性有效度列表)', 'select(弱化有效度列表)', 'select(攻击时属性列表)', 'select(添加技能类型列表)', 'select(封印技能类型列表)', 'select(武器类型列表)', 'select(防具类型列表)', 'select(固定装备列表)', 'select(封印装备列表)', 'select(装备槽类型列表)', 'select(特殊标志列表)', 'select(消失效果列表)', 'select(队伍能力列表)']
            for(const select of selectSymbolArr){
                form.on(select, EditorManager.traitsSelectOnClick);
            }
            // form.on('select(属性有效度列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(弱化有效度列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(攻击时属性列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(添加技能类型列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(封印技能类型列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(武器类型列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(防具类型列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(固定装备列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(封印装备列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(装备槽类型列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(特殊标志列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(消失效果列表)', EditorManager.traitsSelectOnClick);
            // form.on('select(队伍能力列表)', EditorManager.traitsSelectOnClick);
        })
    }

    /**
     * 清空特性选择展示框文本
     */
    static clearDisplayText() {
        const idArr = [64, 63, 62, 55, 54, 53, 52, 51, 44, 43, 42, 41, 35, 32, 31, 14, 13, 12, 11];
        for (const id of idArr) {
            const input = document.getElementById(`traits-show-code${id}`);
            input.value = "";
        }
    }


    /**
     * 添加页面元素事件
     */
    static addEleEvent() {
        //底部按钮逻辑
        layui.use(function () {
            const layer = layui.layer;
            const util = layui.util;
            // 事件
            util.on('lay-on', {
                'changeMax': function () {
                    layer.prompt({title: '请输入最大值'}, function (value, index, elem) {
                        if (value === '') return elem.focus();
                        EditorManager.changeItemMax(value);
                        layer.close(index);
                    });
                },
                'saveToFile': function () {
                    EditorManager.saveToFile();
                }
            })
        })
        //词条名输入监听
        const input = document.getElementById("nameInput");
        input.addEventListener("input", (e) => {
            EditorManager.upDateName(e);
        })
    }

    /**
     * 更新目录列表名称
     */
    static upDateName(e) {
        const value = e.target.value;
        const {id} = layui.form.val("baseInfo");
        if (!id) return;
        const li = document.getElementById(`d-index-${id}`);
        li.innerHTML = `ID-${id}-${value}`;
    }

    /**
     * 清空表格数据
     * @param {string} tableId 表格id
     */
    static clearTableData(tableId) {
        layui.table.reloadData(tableId, {
            data: []
        })
    }

    //====================辅助函数=====================
    /**
     * 属性有效度
     */
    static traitsLayerClick11() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code11"].value;
        const code = 11;
        const name = "属性有效度";
        const min = 1.2;
        const max = 1.5;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[11][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);

    }

    /**
     * 弱化有效度
     */
    static traitsLayerClick12() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code12"].value;
        const code = 12;
        const name = "弱化有效度";
        const min = 1.2;
        const max = 1.5;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[12][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 状态有效度
     */
    static traitsLayerClick13() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code13"].value;
        const code = 13;
        const name = "状态有效度";
        const min = 1.2;
        const max = 1.5;
        const param = input.split(",").map(item => {
            return item.split(":")[1];
        })
        const dataIds = input.split(",").map(item => {
            return Number(item.split(":")[0]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 状态免疫
     */
    static traitsLayerClick14() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code14"].value;
        const code = 14;
        const name = "状态有效度";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",").map(item => {
            return item.split(":")[1];
        })
        const dataIds = input.split(",").map(item => {
            return Number(item.split(":")[0]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 攻击时属性
     */
    static traitsLayerClick31() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code31"].value;
        const code = 31;
        const name = "攻击时属性";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[31][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 攻击时属性
     */
    static traitsLayerClick32() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code32"].value;
        const code = 32;
        const name = "攻击时状态";
        const min = 0.8;
        const max = 1;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",").map(item => {
            return item.split(":")[1];
        })
        const dataIds = input.split(",").map(item => {
            return Number(item.split(":")[0]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 攻击时速度补正
     */
    static traitsLayerClick33() {
        const table = layui.table;
        const code = 33;
        const name = "攻击时速度补正";
        const min = 50;
        const max = 80;
        const param = ["无"];
        const dataIds = [0];
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 攻击时追加次数
     */
    static traitsLayerClick34() {
        const table = layui.table;
        const code = 34;
        const name = "攻击时追加次数";
        const min = 1;
        const max = 3;
        const param = ["无"];
        const dataIds = [0];
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 攻击技能
     */
    static traitsLayerClick35() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code35"].value;
        const code = 35;
        const name = "攻击技能";
        const min = 1;
        const max = 3;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",").map(item => {
            return item.split(":")[1];
        })
        const dataIds = input.split(",").map(item => {
            return Number(item.split(":")[0]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 添加技能类型
     */
    static traitsLayerClick41() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code41"].value;
        const code = 41;
        const name = "添加技能类型";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[41][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 封印技能类型
     */
    static traitsLayerClick42() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code42"].value;
        const code = 42;
        const name = "封印技能类型";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[42][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 添加技能
     */
    static traitsLayerClick43() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code43"].value;
        const code = 43;
        const name = "添加技能";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",").map(item => {
            return item.split(":")[1];
        })
        const dataIds = input.split(",").map(item => {
            return Number(item.split(":")[0]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 封印技能
     */
    static traitsLayerClick44() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code44"].value;
        const code = 44;
        const name = "封印技能";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",").map(item => {
            return item.split(":")[1];
        })
        const dataIds = input.split(",").map(item => {
            return Number(item.split(":")[0]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 装备武器类型
     */
    static traitsLayerClick51() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code51"].value;
        const code = 51;
        const name = "装备武器类型";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[51][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 装备防具类型
     */
    static traitsLayerClick52() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code52"].value;
        const code = 52;
        const name = "装备防具类型";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[52][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 固定装备
     */
    static traitsLayerClick53() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code53"].value;
        const code = 53
        const name = "固定装备";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[53][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 封印装备
     */
    static traitsLayerClick54() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code54"].value;
        const code = 54;
        const name = "封印装备";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[54][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 装备槽类型
     */
    static traitsLayerClick55() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code55"].value;
        const code = 55;
        const name = "装备槽类型";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[55][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 增加行动次数
     */
    static traitsLayerClick61() {
        const table = layui.table;
        const layer = layui.layer;
        const code = 61;
        const name = "增加行动次数";
        const min = 0;
        const max = 2;
        const param = ["无"];
        const dataIds = [0];
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 特殊标志
     */
    static traitsLayerClick62() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code62"].value;
        const code = 62;
        const name = "特殊标志";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[62][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 消失效果
     */
    static traitsLayerClick63() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code63"].value;
        const code = 63;
        const name = "消失效果";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[63][item]);
        })
        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 队伍能力
     */
    static traitsLayerClick64() {
        const table = layui.table;
        const layer = layui.layer;
        const input = window["traits-show-code64"].value;
        const code = 64;
        const name = "队伍能力";
        const min = null;
        const max = null;
        if (input === "") {
            layer.msg("属性不能为空");
            return;
        }
        const param = input.split(",");
        const dataIds = param.map(item => {
            return Number(EditorManager.traitsListEx[64][item]);
        })

        const data = [...table.getData("traitsParamChildren"), {code, dataIds, name, param, min, max}];
        table.reloadData("traitsParamChildren", {
            data: data
        })
        layer.close(EditorManager.tempTraitsLayerIndex);
    }

    /**
     * 特性选择点击事件
     */
    static traitsSelectOnClick(data) {
        const name = data.elem.name;
        const code = name.match(/code(\d{2})/)[1];
        const {value} = data;
        const text = EditorManager.traitsList[code][value];
        const input = document.getElementById(`traits-show-${name}`);
        if (!!input) {
            input.value += input.value === "" ? `${text}` : `,${text}`;
        }
    }

    /**
     * 特性code对照表
     */
    static traitsInterpret() {
        this.traitsList = {
            "11": [...this.systemData.elements],
            "12": ["最大生命值", "最大魔法值", "攻击力", "防御力", "魔法攻击力", "魔法防御力", "敏捷", "幸运"],
            "31": [...this.systemData.elements],
            "41": [...this.systemData.skillTypes],
            "42": [...this.systemData.skillTypes],
            "51": [...this.systemData.weaponTypes],
            "52": [...this.systemData.armorTypes],
            "53": [...this.systemData.equipTypes],
            "54": [...this.systemData.equipTypes],
            "55": ["正常", "二刀流"],
            "62": ["自动战斗", "掩护", "防御", "保留特技值"],
            "63": ["正常", "首领怪", "瞬间消失", "不消失"],
            "64": ["遇敌减半", "无遇敌", "取消偷袭", "增加先发制人率", "双倍金币", "双倍掉落物品"]

        }
    }

    /**
     * 特性文字转id
     */
    static traitsTextToDataId() {
        const keys = Object.keys(this.traitsList);
        const obj = {};
        for (const code of keys) {
            obj[code] = this.reversal(this.traitsList[code]);
        }
        this.traitsListEx = obj;
    }

    /**
     * 反转数组k-v
     * @param obj 数组对象
     * @returns {{}}
     */
    static reversal(obj) {
        const newObj = {};
        for (let i = 0; i < obj.length; i++) {
            const key = obj[i]
            newObj[key] = i;
        }
        return newObj;
    }

    static traitsCodeText = {
        "11": "属性有效度",
        "12": "弱化有效度",
        "13": "状态有效度",
        "14": "状态免疫",
        "31": "攻击时属性",
        "32": "攻击时状态",
        "33": "攻击时速度补正",
        "34": "攻击追加次数",
        "35": "攻击技能",
        "41": "添加技能类型",
        "42": "封印技能类型",
        "43": "添加技能",
        "44": "封印技能",
        "51": "装备武器类型",
        "52": "装备防具类型",
        "53": "固定装备",
        "54": "封印装备",
        "55": "装备槽类型",
        "61": "增加行动次数 ",
        "62": "特殊标志",
        "63": "消失效果",
        "64": "队伍能力"
    }

    /**
     * 在canvas上绘制图标表
     */
    static drawIcon() {
        const imgH = iconImg.height;
        const num = Math.ceil(imgH / 512);
        const x = 0;
        const y = (this.iconPage - 1) * 512;
        const w = 512;
        const h = 512;
        const context = document.getElementById("canvas").getContext("2d");
        context.clearRect(0, 0, w, h)
        context.drawImage(iconImg, x, y, w, h, 0, 0, 512, 512);
    }

    // static icon() {
    //     layer.open({
    //         title: "图标选择",
    //         type: 1,
    //         area: ['512px', '800px'],
    //         content: `<div class="layui-bg-purple"><canvas id="canvas" width="512" height="512"></canvas></div>`
    //     })
    //     const canvas = document.getElementById("canvas").getContext("2d");
    //     canvas.drawImage(window.sunimg, 0, 0);
    //     document.getElementById("canvas").addEventListener("click", function (e) {
    //         console.log(e.offsetX)
    //         console.log(e.offsetY)
    //     })
    //     // layer.closeAll()
    // }
}